home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_c
/
abbrev5
/
ablookup.m
< prev
Wrap
Text File
|
1990-01-22
|
5KB
|
132 lines
;**************************************************************************
;* *
;* ABLOOKUP.CB *
;* *
;* This contains the utility files used both by "abbrev" and *
;* "suffix". Either package may be used alone in conjunction *
;* with this file, and suffix no longer requires the full *
;* abbrev to be used. *
;* *
;* Larry DeMar 10-19-89. *
;* *
;**************************************************************************
;* *
;* AB_LOOKUP *
;* *
;* This is called to look up a string in an abbreviation file. *
;* *
;* Parameter 0 = file part of file name to look in *
;* Parameter 1 = string to lookup *
;* Parameter 2 = global buffer id of system buffer we're using *
;* Parameter 3 = filename for system buffer *
;* *
;* If parameter 2 is non-zero, then it is the id of a *
;* system buffer containing the lookup file. Else, we *
;* create the system buffer. Read the lookup file in, *
;* and put the new buffer id to parameter 2. *
;* *
;* If the string is found to start in column 1 of the *
;* lookup file, then the "return string" is on the *
;* rest of the line in the file. The return string *
;* is put back to parameter 1. *
;* *
;* This returns TRUE of FALSE based on whether the lookup *
;* succeeded. *
;* *
;**************************************************************************
(macro ab_lookup
(
(string file_part
abbreviation
my_search_string
sys_file_name
)
(int orig_buffer
system_id
return_code
)
(set_msg_level 1)
(get_parm 0 file_part)
(get_parm 1 abbreviation)
(get_parm 2 system_id)
(get_parm 3 sys_file_name)
(= orig_buffer (inq_buffer))
(if system_id ; abbrev file in buffer?
(set_buffer system_id) ; yep...go there
;else
(
(= system_id (create_sys_buf file_part sys_file_name)) ; no...create it.
(put_parm 2 system_id) ; and pass it back.
)
)
(top_of_buffer)
(sprintf my_search_string "<%s[ \t]\\c" abbreviation)
(if (= return_code (search_fwd my_search_string 1 0))
(put_parm 1 (trim (ltrim (read))))
)
(set_buffer orig_buffer)
(return return_code)
)
)
;**************************************************************************
;* *
;* CREATE_SYS_BUF *
;* *
;* This is called to create the system buffer and read in *
;* the abbreviation file. *
;* *
;* It returns the id of the buffer it creates. *
;* *
;**************************************************************************
(macro create_sys_buf
(
(int buf_id)
(string file_part
buffer_name
)
(get_parm 0 file_part)
(get_parm 1 buffer_name)
(= buf_id (create_buffer "abbrev_buf" buffer_name 1))
(set_buffer buf_id)
(if (exist (= file_part (get_abbrev_file file_part)))
(read_file file_part) ; read in the file
)
(return buf_id)
)
)
;**************************************************************************
;* *
;* GET_ABBREV_FILE *
;* *
;* This is called to return the full path of the abbrev *
;* directory file. *
;* *
;* 1) if BABBREV is in environment, then it is *
;* used as the path. *
;* *
;* 2) if BPATH is in environment, then it is *
;* used as the path. *
;* *
;* 3) otherwise "C:\" is used as the path. *
;* *
;**************************************************************************
(macro get_abbrev_file
(
(string abbrev_path
file_part
)
(int semi_spot)
(get_parm 0 file_part)
(if (== (= abbrev_path (inq_environment "BABBREV")) "")
(if (== (= abbrev_path (inq_environment "BPATH")) "")
(= abbrev_path "c:")
;else
(if (= semi_spot (rindex abbrev_path ";"))
(= abbrev_path (substr abbrev_path (+ semi_spot 1)))
)
)
)
(return (+ (trim (ltrim abbrev_path)) (+ "\\" file_part)))
)
)